<!--
 * @description: 第三方系统账号绑定成功后，后端接口重定向到该页面，
 * 并从url中获取绑定状态
 * @author: huangpeng
 * @date: 2025年01月021日 15:14
 * @Copyright:  2022-2025
!-->
<template>
  <div style="padding: 20px;">
    <h1>{{ dvBindStatus ? '恭喜你，第三方账号绑定成功，当前页面即将关闭！' : '第三方账号绑定中...' }}</h1>
  </div>
</template>
<script lang="ts">
import {Component, Vue} from "vue-property-decorator";
import {insertThirdBind} from "@/api/auth/login";
import cache from "@/plugins/cache";

@Component({})
export default class thirdLogin extends Vue {

  /** 账号绑定状态 */
  public dvBindStatus : any = false;

  /** 用户绑定第三方信息状态 */
  get thirdBindStatus() {
    return cache.local.get("thirdBindStatus");
  }

  private created() {
    // 获取url上携带的数据
    let data = this.getParamMap();
    this.dvBindStatus = false;
    insertThirdBind(data).then(res => {
      this.dvBindStatus = true;
      this.$message.success("恭喜你，第三方账号绑定成功，当前页面即将关闭！");
      cache.local.set("thirdBindStatus", 'true');
      setTimeout(() => {
        window.close();
      }, 2000);
    })
  }

  /** 解析url中的token和用户名参数 */
  private getParamMap(): any {
    const url = window.document.location.href.toString();//获得当前url地址并转换成字符串
    let params = url.split("?");//以？来分割字符串，将？前后的值存到一个数组中
    params = params[1].split("&");
    let result: any = {};
    for (let param of params) {
      const paramItem = param.split("=");
      result[paramItem[0]] = decodeURIComponent(paramItem[1]);
    }
    return result;
  }
}
</script>
<style scoped lang="scss">
</style>
